function [new_mix new_vars] = killComponents(old_mix, old_vars, kill_inds)


new_mix = old_mix;

new_mix.priors(kill_inds) = [];
new_mix.priors = new_mix.priors/sum(new_mix.priors);
new_mix.centres(kill_inds, :) = [];
new_mix.covars(:, :, kill_inds) = [];
new_mix.ncentres = numel(new_mix.priors);

if isfield(new_mix, 'varposterior');
    if isfield(new_mix.varposterior, 'a')
        new_mix.varposterior.a(kill_inds) = [];
    end
    if isfield(new_mix.varposterior, 'm')
        new_mix.varposterior.m(kill_inds, :) = [];
    end
    if isfield(new_mix.varposterior, 'b')
        new_mix.varposterior.b(kill_inds) = [];
    end
    if isfield(new_mix.varposterior, 'W')
        new_mix.varposterior.W(:, :, kill_inds) = [];
    end
    if isfield(new_mix.varposterior, 'v')
        new_mix.varposterior.v(kill_inds) = [];
    end
    if isfield(new_mix.varposterior, 'T')
        new_mix.varposterior.T(:, :, kill_inds) = [];
    end

    if isfield(new_mix.varposterior, 'ElndetLambda')
        new_mix.varposterior.ElndetLambda(kill_inds) = [];
    end
end


K = new_mix.ncentres;


new_vars = old_vars;
if isfield(new_vars, 'Z')
    new_vars.Z(:, kill_inds) = [];   % using logical indexing
    new_vars.Z = new_vars.Z + realmin;
    new_vars.Z = new_vars.Z./(sum(new_vars.Z, 2)*ones(1, K));
end
if isfield(new_vars, 'R')
    new_vars.R(:, :, kill_inds) = [];
    new_vars.RRt(:, :, :, kill_inds) = [];
end
if isfield(new_vars, 'E')
    new_vars.E(:, :, :, kill_inds) = [];
end
if isfield(new_vars, 'logdetE')
    new_vars.logdetE(:, kill_inds) = [];
end
